String clazzTpl({package}) => """
import 'app_debug_model.dart';
import 'package:xanno/xanno.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:$package/store/app_state.dart';
import 'package:$package/route/main.route.dart';
import 'package:path_provider/path_provider.dart';
import 'package:$package/widget/theme_builder.dart';
import 'package:$package/store/user/user_state.dart';
import 'package:$package/store/theme/theme_state.dart';
import 'package:observable_builder/observable_builder.dart';

@GRoute(url: '/appDebug', title: 'AppDebug')
class AppDebugPage extends StatelessWidget {
  final String title;

  const AppDebugPage({Key? key, required this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ThemeBuilder(builder: (context, theme) {
      return ObservableBuilder<UserState>(
          create: AppState.observableUser,
          memo: (state) => [state.appDebug],
          builder: (context, state) {
            return Scaffold(
              backgroundColor: theme.body,
              appBar: AppBar(
                brightness: theme.type == ThemeType.light
                    ? Brightness.light
                    : Brightness.dark,
                backgroundColor: theme.body,
                iconTheme: IconThemeData(color: theme.title, opacity: 1),
                title: Text(
                  title,
                  style: TextStyle(color: theme.title),
                ),
              ),
              body: ListView.separated(
                itemCount: state.appDebug!.length,
                separatorBuilder: (BuildContext context, int index) {
                  return Divider(height: 1);
                },
                itemBuilder: (BuildContext context, int index) {
                  AppDebugModel item = state.appDebug![index];
                  return GestureDetector(
                    onTap: () async {
                      if (item.key == AppDebugKey.errorLog) {
                        final dir = await getApplicationDocumentsDirectory();
                        Navigator.pushNamed(
                            context, RouteConstant.AppErrorLogPage,
                            arguments: ErrorLogFileModel(
                                path: dir.path, title: '日志列表', isFile: false));
                      }
                    },
                    child: ListTile(
                      title: Text(
                        item.title,
                        style: TextStyle(color: theme.body),
                      ),
                      subtitle: Text(
                        '\${item.on ? '开启' : '关闭'}功能',
                        style: TextStyle(color: theme.body),
                      ),
                      tileColor: theme.title.withOpacity(0.8),
                      trailing: [AppDebugKey.errorLog].contains(item.key)
                          ? Icon(Icons.keyboard_arrow_right,
                              size: 30, color: theme.body)
                          : CupertinoSwitch(
                              activeColor: Colors.green,
                              trackColor: theme.body.withOpacity(0.8),
                              value: item.on,
                              onChanged: (bool value) {
                                item.on = !item.on;
                                AppState.observableUser.notify((state) {
                                  state.updateAppDebug(item);
                                });
                              },
                            ),
                    ),
                  );
                },
              ),
            );
          });
    });
  }
}
""";
